home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_cyrus-imapd.idb / usr / freeware / bin / installsieve.z / installsieve
Text File  |  2001-07-06  |  5KB  |  167 lines

  1. #! /bin/sh
  2. exec /usr/bin/perl5 -x -S $0 ${1+"$@"} # -*-perl-*-
  3. #!perl -w
  4. # Copyright (c) 2000 Carnegie Mellon University.  All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. #
  10. # 1. Redistributions of source code must retain the above copyright
  11. #    notice, this list of conditions and the following disclaimer. 
  12. #
  13. # 2. Redistributions in binary form must reproduce the above copyright
  14. #    notice, this list of conditions and the following disclaimer in
  15. #    the documentation and/or other materials provided with the
  16. #    distribution.
  17. #
  18. # 3. The name "Carnegie Mellon University" must not be used to
  19. #    endorse or promote products derived from this software without
  20. #    prior written permission. For permission or any other legal
  21. #    details, please contact  
  22. #      Office of Technology Transfer
  23. #      Carnegie Mellon University
  24. #      5000 Forbes Avenue
  25. #      Pittsburgh, PA  15213-3890
  26. #      (412) 268-4387, fax: (412) 268-7395
  27. #      tech-transfer@andrew.cmu.edu
  28. #
  29. # 4. Redistributions of any form whatsoever must retain the following
  30. #    acknowledgment:
  31. #    "This product includes software developed by Computing Services
  32. #     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
  33. #
  34. # CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
  35. # THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  36. # AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
  37. # FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  38. # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  39. # AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  40. # OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  41. #
  42. use Cyrus::SIEVE::managesieve;
  43. use Getopt::Long;
  44.  
  45. $username = "";
  46.  
  47. $ret = GetOptions("v|views:s" => \$views,
  48.           "l|list" => \$list,
  49. #          "p|port:i" => \$port,
  50.           "i|installs:s" => \$installs,
  51.           "a|activates:s" => \$activates,
  52.           "d|deletes:s" => \$deletes,
  53. #          "m|mechanism:s" => \$mech,
  54.           "g|gets:s" => \$gets,
  55.                   "u|username:s" => \$username,
  56. #          "w|password:s" => \$pass
  57.                   );
  58. if (!$ret || $#ARGV != 0) { 
  59.     show_help();
  60.     exit;
  61. }
  62.  
  63. $acapserver = $ARGV[0];
  64.  
  65. sub list_cb {
  66.  
  67.   my($name, $isactive) = @_ ;
  68.   
  69.   print "$name ";
  70.   if ($isactive == 1) {
  71.     print " <- active script\n";
  72.   } else {
  73.     print "\n";
  74.   }
  75.  
  76. }
  77.  
  78. sub prompt {
  79.  
  80.   my($type, $prompt) = @_ ;
  81.  
  82.   if (($type eq "username") && (defined $username)) {
  83.       return $username;
  84.   } elsif (($type eq "authname") && (defined $username)) {
  85.       return $username;
  86.   } elsif (($type eq "realm") && (defined $realm)) {
  87.       return $realm;
  88.   }
  89.  
  90.   print "$prompt: ";
  91.  
  92.   $b = <STDIN>;
  93.   chop($b);
  94.   
  95.   $b;
  96. }
  97.  
  98. sub show_help {
  99.   print "NOTE: This program is deprecated. Please use sieveshell\n";
  100.   print "\n";
  101.   print "Usage:\n";
  102.   print "  installsieve [options] <server>\n";
  103.   print "\n";
  104.   print "  -v <name>    view script\n";
  105.   print "  -l           list available scripts\n";
  106. #  print "  -p <port>    port to connect to\n";
  107.   print "  -i <file>    filename of script to install\n";
  108.   print "  -a <name>    Set <name> as the active script\n";
  109.   print "  -d <name>    Delete <name> script from server\n";
  110. #  print "  -m <mech>    Mechanism to use for authentication\n";
  111.   print "  -g <name>    Get script <name> and save to disk\n";
  112.   print "  -u <user>    Userid/Authname to use\n";
  113. #  print "  -w <passwd>  Specify password (Should only be used for automated scripts)\n";
  114.   print "\n";
  115. }
  116.  
  117. #main code
  118.  
  119. my $obj = sieve_get_handle($acapserver,"prompt","prompt","prompt","prompt");
  120.  
  121. if (!defined $obj) {
  122.   die "Unable to connect to server";
  123. }
  124.  
  125. if (defined $installs) {
  126.   $ret = sieve_put_file($obj, $installs);
  127.   if ($ret != 0) { print "upload failed\n"; }
  128. }
  129.  
  130. if (defined $deletes) {
  131.   $ret = sieve_delete($obj, $deletes);
  132.   if ($ret != 0) { print "delete failed\n"; }
  133. }
  134.  
  135. if (defined $activates) {
  136.   $ret = sieve_activate($obj, $activates);
  137.   if ($ret != 0) { print "activate failed\n"; }
  138. }
  139.  
  140. if (defined $gets) {
  141.     $str = "";
  142.     $ret = sieve_get($obj, $gets, $str);
  143.     if ($ret != 0) { 
  144.     print "get failed\n"; 
  145.     } else {
  146.     open (OUTPUT,">$gets") || die "Unable to open $gets";
  147.     print OUTPUT $str;
  148.     close(OUTPUT);    
  149.     }
  150. }
  151. if (defined $views) {
  152.     $str = "";
  153.     $ret = sieve_get($obj, $views, $str);
  154.     if ($ret != 0) { 
  155.     print "get failed\n"; 
  156.     } else {
  157.     # view
  158.     print $str;
  159.     }
  160. }
  161.  
  162. if (defined $list) {
  163.   $ret = sieve_list($obj, "list_cb");  
  164.   if ($ret != 0) { print "List command failed\n"; }
  165. }
  166.